%ifndef TYPE_CHECK_ASM
%define TYPE_CHECK_ASM

section .data
err1_1_ty	db	"ERROR 1. TYPE ERROR. got "
err1_1_len:
err1_2_ty	db	" but wanted "
err1_2_len:
err1_3_ty	db	"."
err1_3_len:

section .text

;; NOTE:
;; in the case of 0b000 this only checks those 3 bits, it should realy check all 5 bits

type_check:
	;; got in: RAX
	;; wanted in: R8

	mov	rcx, rax
	and	rcx, 0b111
	cmp	rcx, r8
	
	jne	.type_error
	ret

.type_error:
	push	rax
	
	mov	rax, sys_write
	mov	rdi, 0
	mov	rsi, err1_1_ty
	mov	rdx, (err1_1_len - err1_1_ty)
	syscall

	pop	rax
	call	print_type

	mov	rax, sys_write
	mov	rdi, 0
	mov	rsi, err1_2_ty
	mov	rdx, (err1_2_len - err1_2_ty)
	syscall

	mov	rax, r8
	call	print_type

	mov	rax, sys_write
	mov	rdi, 0
	mov	rsi, err1_3_ty
	mov	rdx, (err1_3_len - err1_3_ty)
	syscall
	
	mov	rax, sys_exit
	mov	rdi, 0
	syscall

%endif
